import { ProjectInfo, ProjectPlatform } from "@/ts/interfaces/project.interfaces"

const PLATFORM_NAME_MAP = {
  android: 'Android',
  browser: 'Browser',
  windows: 'Windows',
  ios: 'iOS',
  linux: 'Linux',
  macos: 'macOS',
  openharmony: 'OpenHarmony'
}
const PLATFORM_LIST: ProjectPlatform[] = ['android', 'windows', 'ios', 'linux', 'macos', 'openharmony', 'browser']

/**
 * 获取项目的默认平台
 * @param prjInfo
 * @param selectedPlatforms
 * @returns
 */
export function getProjectDefaultPlatform(prjInfo: ProjectInfo, selectedPlatforms: ProjectPlatform[]): ProjectPlatform | null {
  for (const selectedPlatform of selectedPlatforms) {
    if (prjInfo.platforms[selectedPlatform])
      return selectedPlatform
  }
  // 浏览器是通用的，所以首先返回浏览器
  if (prjInfo.platforms.browser)
    return 'browser'
  else for (const selectedPlatform of getSupportedPlatforms()) {
    if (prjInfo.platforms[selectedPlatform])
      return selectedPlatform
  }
  return null
}

export function getProjectDefaultFlavor(prjInfo: ProjectInfo) {

}

export function getSupportedPlatforms(): ProjectPlatform[] {
  return [...PLATFORM_LIST]
}

export function convertPlatform2Name(platform: ProjectPlatform): string {
  return PLATFORM_NAME_MAP[platform]
}
